import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  let piniaCart=ref([])
  let piniaAddCart=(detail,goods_id)=>{
    let username=localStorage.getItem('username')
    let pdCart=piniaCart.value.find(item=>item.goods.goods_id==goods_id)
    if(pdCart){
      pdCart.number++
    }else{
      piniaCart.value.push({
        username:username,
        id:Math.floor(Math.random()*100000),
        number:1,
        goods:detail,
        checked:false
      })
    }
  }
  return { piniaCart,piniaAddCart }
},
{
  persist:true
}
)
